<?php

	//Visa lista och skit.
	class FileUploadView {
		
		private $uploadButton = "uploadButton";
		
		public function UploadForm() {
			
			return "
				<form action='' method='post' enctype='multipart/form-data'>
					<p><input type='file' name='file' id='file' /></p>
					<p><input type='submit' name='$this->uploadButton' value='Upload' class='button' /></p>
				</form>";
		}
		
		//Skriver ut lista med filerna.
		public function FileList() {
			
			$div = "";
			$dir = opendir("files/");
			
			while (($file = readdir($dir)) !== false) {
				if (($file != ".") && ($file != "..")) {
					$div .= "<img src='files/$file' height='50px' width='100px' class='imageBlock'>";
				}
			}
			
			closedir($dir);
			
			return "<h2>Uploaded Images:</h2>" . $div;
		}
		
		public function ErrorMessage() {
			return "
				<div id='wrongFileDiv'>
					<p class='wrongFileText'>The file is invalid or already exists.</p>
				</div>";
		}
		
		public function Files() {
			return $_FILES[0];
		}
		
		public function UploadButton() {
			if (isset($_POST[$this->uploadButton]) == true) {
				return true;
			}		
			return false;
		}
	}
